﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace _22.Exercise
{
    class Program
    {
        static void Main(string[] args)
        {
            string a = "car bar car water women   man ?... goal women final man men !!!@ bal car";            
            Dictionary<string, int> words = new Dictionary<string, int>();           
            MatchCollection matches = Regex.Matches(a, @"\w+");
            foreach (Match item in matches)
            {
                if (words.ContainsKey(item.Value))
                {
                    words[item.ToString()] = words[item.Value] + 1;
                }
                else
                {
                    words.Add(item.Value, 1);
                    
                }
            }            
            foreach (KeyValuePair<string,int> item in words)
            {
                Console.WriteLine(item);
            }
            //foreach (Match word in Regex.Matches(a, @"\w+"))
            //    words[word.Value] = words.ContainsKey(word.Value) ? words[word.Value] + 1 : 1;
        }
    }
}
